#!/usr/bin/env bash
SCRIPT_DIR=`dirname $0`
OLD_LABEL=$3
OLD_FILE=$6

NEW_LABEL=$5
NEW_FILE=$7

TMP_FILE=`mktemp /tmp/svn_smart_diffXXXXXXX`

icdiff -u "$OLD_FILE" "$NEW_FILE" --label="$OLD_LABEL" --label="$NEW_LABEL" --line-numbers > $TMP_FILE

LINES_COUNT=`cat "$TMP_FILE" | wc -l`
LINES_THRESHOLD=40

STATUS=1
if [ "$LINES_COUNT" -gt "$LINES_THRESHOLD" ];
then
    python $SCRIPT_DIR/svn_diff.py "$@"
    STATUS=$?
fi

if [ "$STATUS" -ne "0" ];
then
    cat "$TMP_FILE"
fi

if [ "$STATUS" -ne "0" ];
then
    echo
    read
fi

rm "$TMP_FILE"

